<?php

	namespace app\home\controller;

	use app\home\model\ThemeGoods;
	use app\home\validate\ThemeValidate;
	use think\Controller;
	use think\Request;

	class Theme extends Base
	{
		public function getTheme () {
			$themeModel = new \app\home\model\Theme();
			$list = $themeModel->field('id,image')->select();

			return success($list);
		}


		public function getThemeGoodsList () {

			$themeValidate = new ThemeValidate();
			$validateRes = $themeValidate->goSceneCheck('getThemeGoodsList');
			if ($validateRes) {
				return error($validateRes);
			}

			$id = intval($this->request->post('id'));
			$themeModel = new \app\home\model\Theme();
			$theme = $themeModel->where('id', $id)->find();
			$goodsModel = new \app\home\model\Goods();
			$theme['list'] = $goodsModel->alias('g')->join('theme_goods tg','tg.goods_id = g.id')->where('tg.theme_id',$id)->select();

			if ($theme) {
				return success($theme);
			}

			return error('联系管理员添加数据');
		}


	}
